import { ref } from "vue";
import { defineStore } from 'pinia'

const dictStore = defineStore("dict", () => {
    //字典数据
    const dictOptions = ref({})

    const dictList = [
        6008801, //来源厂商
        6008802, //运营商
        6008803, //工作频段
        6008804, //设备类型
    ]

    //获取字典项
    const getDictData = () => {
        // let res = await GetSomeDicts(dictList)
        // if (res.code === 0) {
        //     const { result } = res;
        //     for (let key in result) {
        //         let _list = [];
        //         result[key].forEach(v => {
        //             _list.push({
        //                 value: v.dictionaryNo,
        //                 label: v.dictionaryValue
        //             })
        //         });
        //         dictOptions.value[key] = _list;
        //     }
        // }
    }
    getDictData()

    //获取字典翻译值
    const getDictLabel = (val, dict) => {
        let _obj = dictOptions.value[dict] && dictOptions.value[dict].find(item => item.value == val);
        return _obj ? _obj.label : undefined;
    }

    return {
        dictOptions,
        getDictLabel
    }
})

export default dictStore;
